using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Portal.Core.DAL;

namespace Portal.BO.Editoral.Tag_Image
{
    public static class TagImageHelper
    {
        public static DataTable GetListPosition(string image_id)
        {
            DataTable dt;
            using (MainDB objDb = new MainDB())
            {
                dt = (DataTable)objDb.CallStoredProcedure("GetListTagImageByImageID", new object[] { image_id }, new string[] { "@image_id" }, true);
            }

            return dt;
        }

        public static string GetArrayNote(string image_id)
        {
            string strReturn = "";
            DataTable dt = GetListPosition(image_id);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                strReturn += "{\"x1\":\"" + dt.Rows[i]["left"] + "\",\"y1\":\"" + dt.Rows[i]["top"] + "\",\"height\":\"" + dt.Rows[i]["height"] + "\",\"width\":\"" + dt.Rows[i]["width"] + "\",\"note\":\"" + dt.Rows[i]["note"].ToString().Replace("\"","\\\"") + "\", \"price\":\"" + dt.Rows[i]["price"] + "\",\"shop\":\"" + dt.Rows[i]["shop"] + "\", \"Logo\": \"" + dt.Rows[i]["logo"] + "\", \"product\":\"" + dt.Rows[i]["product"] + "\"},";
            }

            if (strReturn != "")
                strReturn = strReturn.TrimEnd(',');

            return strReturn;
        }

        public static void InsertTagImage(string Image_ID, string news_id, string left, string top, string height, string width, string price, string shop, string note, string logo, string product)
        {
            using (MainDB objDb = new MainDB())
            {
                objDb.CallStoredProcedure("Tag_ImageInsert", new object[] { Image_ID, news_id, left, top, height, width, price, shop, note, logo, product },
                                                             new string[] { "@Image_ID", "@news_id", "@left", "@top", "@height", "@width", "@price", "@shop", "@note", "@logo", "@product" }, false);
            }
        }

        public static void UpdateTagImage(string Image_ID, string left, string top, string height, string width, string price, string shop, string note, string logo, string product, string old_left, string old_top, string old_height, string old_width)
        {
            using (MainDB objDb = new MainDB())
            {
                objDb.CallStoredProcedure("Tag_ImageUpdate", new object[] { Image_ID, left, top, height, width, price, shop, note, logo, product, old_left, old_top, old_height, old_width },
                                                             new string[] { "@Image_ID", "@left", "@top", "@height", "@width", "@price", "@shop", "@note", "@logo", "@product", "@old_left", "@old_top", "@old_height", "@old_width" }, false);
            }
        }

        public static void Tag_ImageDeleteByPosition(string Image_ID, string left, string top, string height, string width)
        {
            using (MainDB objDb = new MainDB())
            {
                objDb.CallStoredProcedure("Tag_ImageDeleteByPosition", new object[] { Image_ID, left, top, height, width },
                                                                        new string[] { "@Image_ID", "@left", "@top", "@height", "@width" }, false);
            }
        }
    }
}
